﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BomberManServer.Gaming.Object.Mapping.Model.States;
using BomberManServer.Utils;
using BomberManServer.Gaming.Object.Bonuses;

namespace BomberManServer.Gaming.Object.Mapping.Model.Maps
{
    class Melee : Map
    {
        private Trap trap;
        public Melee(Game game) : base(game,21,21)
        {
            Zone zone1 = new Zone(Constants.instance.nbBonusMelee, game);
            Zone zone2 = new Zone(Constants.instance.nbBonusMelee, game);
            Zone zone3 = new Zone(Constants.instance.nbBonusMelee, game);
            Zone zone4 = new Zone(Constants.instance.nbBonusMelee, game);
            builders.Add(zone1);
            builders.Add(zone2);
            builders.Add(zone3);
            builders.Add(zone4);
            trap = new Trap(game.scheduler, game.sender);

            // free blocks in exterior
            for(UInt32 index=2;index<10;index++)
            {
                blocks.at(1, index).state = Constants.instance.stateFree;
                blocks.at(1, 20 - index).state = Constants.instance.stateFree;

                blocks.at(index, 1).state = Constants.instance.stateFree;
                blocks.at(20 - index, 1).state = Constants.instance.stateFree;

                blocks.at(19, index).state = Constants.instance.stateFree;
                blocks.at(19, 20 - index).state = Constants.instance.stateFree;

                blocks.at(index, 19).state = Constants.instance.stateFree;
                blocks.at(20 - index, 19).state = Constants.instance.stateFree;
            }

            blocks.at(9, 2).state = Constants.instance.stateFree;
            blocks.at(9, 3).state = Constants.instance.stateFree;
            blocks.at(11, 2).state = Constants.instance.stateFree;
            blocks.at(11, 3).state = Constants.instance.stateFree;

            blocks.at(2, 9).state = Constants.instance.stateFree;
            blocks.at(3, 9).state = Constants.instance.stateFree;
            blocks.at(2, 11).state = Constants.instance.stateFree;
            blocks.at(3, 11).state = Constants.instance.stateFree;

            blocks.at(9, 18).state = Constants.instance.stateFree;
            blocks.at(9, 17).state = Constants.instance.stateFree;
            blocks.at(11, 18).state = Constants.instance.stateFree;
            blocks.at(11, 17).state = Constants.instance.stateFree;

            blocks.at(18, 9).state = Constants.instance.stateFree;
            blocks.at(17, 9).state = Constants.instance.stateFree;
            blocks.at(18, 11).state = Constants.instance.stateFree;
            blocks.at(17, 11).state = Constants.instance.stateFree;

            // set spawn points
            blocks.at(1, 1).state = new Spawn(game.match.players[0],1,1);
            blocks.at(19, 1).state = new Spawn(game.match.players[1],19,1);
            blocks.at(19, 19).state = new Spawn(game.match.players[2],19,19);
            blocks.at(1, 19).state = new Spawn(game.match.players[3],1,19);
            
            for(UInt32 index=4;index < 8; index++)
            {
                if (index % 2 == 1)
                {
                    blocks.at(10, index).state = destructible;
                    blocks.at(index, 10).state = destructible;
                    blocks.at(10, 20 - index).state = destructible;
                    blocks.at(20 - index, 10).state = destructible;
                }
                blocks.at(9, index).state = destructible;
                blocks.at(11, index).state = destructible;

                blocks.at(index, 9).state = destructible;
                blocks.at(index, 11).state = destructible;

                blocks.at(9, 20 - index).state = destructible;
                blocks.at(11, 20 - index).state = destructible;

                blocks.at(20 - index, 9).state = destructible;
                blocks.at(20 - index, 11).state = destructible;

            }
            
            // the square for the zones            
            for(UInt32 x = 2; x <= 8;x++)
                for (UInt32 y = 2; y <= 8; y++)
                {
                    // if x or y is not pair
                    if ((x % 2 == 0) && (y % 2 == 0)) continue;
                    //for slab
                    if ((x == 8) && (y == 8))
                        continue;
                    if ( (x > 6) && (y > 6) )
                    {
                        // the corners
                        blocks.at(x, y).state = destructible;
                        blocks.at(20 - x, y).state = destructible;
                        blocks.at(x, 20 - y).state = destructible;
                        blocks.at(20 - x, 20 - y).state = destructible;
                        continue;
                    }

                    zone1.attach(blocks.at(x, y));
                    zone2.attach(blocks.at(20 - x, y));
                    zone3.attach(blocks.at(x, 20 - y));
                    zone4.attach(blocks.at(20 - x, 20 - y));
                }
            
            // bonuses
            blocks.at(10, 3).state = new Bonus(game,Items.Bonus.Type.RANGE);
            blocks.at(3, 10).state = new Bonus(game, Items.Bonus.Type.SPEED);
            blocks.at(10, 17).state = new Bonus(game, Items.Bonus.Type.BOMB);
            blocks.at(17, 10).state = new Bonus(game, Items.Bonus.Type.DELAY);

            // Trap
            blocks.at(10, 10).state = new States.Trap(trap,new BonusTemp(game,Items.Bonus.Type.KICK));

            // slabs
            blocks.at(8, 8).state = trap.slab;
            blocks.at(8, 12).state = trap.slab;
            blocks.at(12, 8).state = trap.slab;
            blocks.at(12, 12).state = trap.slab;

            // destructible in the center
            blocks.at(9, 10).state = destructible;
            blocks.at(8, 10).state = destructible;
            blocks.at(11, 10).state = destructible;
            blocks.at(12, 10).state = destructible;

            blocks.at(10, 8).state = destructible;
            blocks.at(10, 9).state = destructible;
            blocks.at(10, 11).state = destructible;
            blocks.at(10, 12).state = destructible;

            zone1.initialize();
            zone2.initialize();
            zone3.initialize();
            zone4.initialize();
        }
    }
}
